Page({
  data: {
    driverLicense: [],
    healthCertificate: []
  },

  chooseImage: function (e) {
    const field = e.currentTarget.dataset.field;
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      success: (res) => {
        if (field === 'driverLicense') {
          this.setData({
            driverLicense: res.tempFiles.map(file => file.tempFilePath)
          });
        } else {
          this.setData({
            healthCertificate: res.tempFiles.map(file => file.tempFilePath)
          });
        }
      }
    });
  },

  deleteImage: function (e) {
    const field = e.currentTarget.dataset.field;
    const index = e.currentTarget.dataset.index;
    if (field === 'driverLicense') {
      const newDriverLicense = this.data.driverLicense.filter((_, i) => i!== index);
      this.setData({
        driverLicense: newDriverLicense
      });
    } else {
      const newHealthCertificate = this.data.healthCertificate.filter((_, i) => i!== index);
      this.setData({
        healthCertificate: newHealthCertificate
      });
    }
  },

  formSubmit: function (e) {
    const formData = e.detail.value;
    const { driverLicense, healthCertificate } = this.data;
    // 这里可以添加提交数据到服务器的逻辑
    wx.showToast({
      title: '提交成功',
      icon:'success'
    });
    console.log('表单数据：', formData);
    console.log('驾驶证照片：', driverLicense);
    console.log('健康证照片：', healthCertificate);
  }
});